package com.yuanfeng.job.job;

import com.yuanfeng.job.dto.PromotionDTO;
import com.yuanfeng.job.mapper.PromotionMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @ClassName PromotionJob
 * @Description 订单超过售后期满足条件会员晋升
 * @Author liulh
 * @Date 2023/5/17 9:52
 * @Version 1.0
 **/
public class PromotionJob implements BaseJob {

    @Autowired
    private PromotionMapper promotionMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //查询会员等级删除了的用户
        List<PromotionDTO> promotionList = promotionMapper.getPromotionByOrder();
        for (PromotionDTO promotion : promotionList) {
            Integer integral = promotionMapper.getUserIntegralByOrder(promotion.getUserId());
            Integer userIntegral = (promotion.getUserIntegral() == null ? 0 : promotion.getUserIntegral()) +
                    (integral == null ? 0 : integral);
            Integer gradeId = promotionMapper.getGradeIdByUserIntegral(userIntegral);
            promotionMapper.updateGradeId(gradeId,promotion.getUserId());
        }
    }
}